<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<title>消息</title>
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/common.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
	<style>
		html,
		body {
			width: 100%;
			min-height: 100%;
			background: #f0f0f0;
		}

		.h10 {
			height: 10px;
			background: #f0f0f0;
		}

		.h1 {
			height: 1px;
			margin-left: 15px;
			background: #f0f0f0;
		}

		.fr {
			float: right;
		}

		.hint {
			color: #666;
			font-size: 12px;
			margin-right: 5px;
		}

		.aui-title {
			color: #fff
		}

		#header_top {
			background: #2997e4;
			/*padding-top: 25px;*/
		}

		.presshover {
			background-color: #FAFAFA;
		}
	</style>
</head>

<body>

	<div id="wrap">

		<header id="header_top" class="aui-bar aui-bar-nav" style="">

			<div class="aui-title">消息</div>
			<!-- <a class="aui-pull-right">
	        <span class="aui-iconfont aui-icon-search"></span>
	    </a> -->
		</header>

		<div class="aui-tab" id="tab" style="width:100%">
			<div class="aui-tab-item aui-active">聊天
				<div class="aui-badge aui-hide"></div>
			</div>
			<div class="aui-tab-item">
				<div></div>通知
				<div class="aui-badge aui-hide">0</div>
			</div>

		</div>

		<div id="main">

		</div>
		<div class="h10"></div>




	</div>
	<div class="h10"></div>
	<div class="h10"></div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/aui-tab.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<!-- <script type="text/javascript" src="../../script/axios.min.js"></script>
<script type="text/javascript" src="../../script/axios-config.js"></script> -->


<script type="text/javascript">
	// 完成首页初始化

	apiready = function() {

			// alert($api.getStorage('home_tz_num'));
		//首页如果有获取到未读的通知推送
		if ($api.getStorage('home_tz_num') && $api.getStorage('home_tz_num')!=0) {
			$('.aui-badge').eq(1).removeClass('aui-hide');
			$('.aui-badge').eq(1).html($api.getStorage('home_tz_num'));
		}

		var header_top = $api.byId('header_top');
		var header_topPos = $api.offset(header_top);
		$api.fixStatusBar(header_top);

		openNewWindow(1)


		api.addEventListener({
			name: 'send_notice_num'
		}, function(ret, err) {
			//  console.log('tongzhih de yige xiaoxi '+JSON.stringify(ret));
			if (ret) {

				if (ret.value.notice_num != 0) {
					$('.aui-badge').eq(1).removeClass('aui-hide');
					$('.aui-badge').eq(1).html(ret.value.notice_num);
				} else {
					$('.aui-badge').eq(1).addClass('aui-hide');
				}

			} else {
				console.log('获取通知列表个数失败' + JSON.stringify(err));
			}
		});


		api.addEventListener({
			name: 'send_info_num'
		}, function(ret, err) {
			//  alert("shoudaode xiaoxi zongshu "+JSON.stringify(ret));
			if (ret) {

				if (ret.value.msg_num != 0) {
					$('.aui-badge').eq(0).removeClass('aui-hide');
					$('.aui-badge').eq(0).html(ret.value.msg_num);
				} else {
					$('.aui-badge').eq(0).addClass('aui-hide');
				}

			} else {
				console.log('获取消息列表个数失败' + JSON.stringify(err));
			}
		});



		api.addEventListener({
		    name: 'xiugai_tz'
		}, function(ret, err){
		    if( ret ){
							console.log('jeishou jianting xiaoxi ')
							var tz_num = parseInt($('.aui-badge').eq(1).html())-1;
							console.log(tz_num)
							if(tz_num>0){
									$('.aui-badge').eq(1).removeClass('aui-hide');
									$('.aui-badge').eq(1).html(tz_num);
							}else{
								$('.aui-badge').eq(1).addClass('aui-hide');
							}


		    }else{
		        //  alert( JSON.stringify( err ) );
		    }
		});



	}

	function openNewWindow(index) {
		var header_top = $api.byId('header_top');
		var header_topPos = $api.offset(header_top);
		var tab = $api.byId('tab');
		var tabPos = $api.offset(tab);

		if (index == 1) {
			//用户消息
			api.openFrame({
				name: 'user_info',
				url: './user_info.html',
				rect: {
					x: 0,
					y: header_topPos.h + tabPos.h,
					w: 'auto',
					h: api.frameHeight - (header_topPos.h + tabPos.h)
				},
				bounces: false,
				delay: 200,
				bgColor: '#fff'
			});
		} else {

			//api.closeWin({name:'user_info'});
			//通知
			api.openFrame({
				name: 'user_notic',
				url: './user_notic.html',
				rect: {
					x: 0,
					y: header_topPos.h + tabPos.h,
					w: 'auto',
					h: api.frameHeight - (header_topPos.h + tabPos.h)
				},
				bounces: false,
				delay: 200,
				bgColor: '#fff'
			});
		}

	}



	var tab = new auiTab({
		element: document.getElementById("tab"),
		callback: function(o, dom) {


		},
		repeatClick: false
	}, function(ret) {
		// console.log(ret)
		openNewWindow(ret.index)
	});



</script>

</html>
